package com.huawei.hianalytics.ab.bc.fg;

import android.text.TextUtils;
import com.huawei.hianalytics.ab.bc.kl.de;
import com.huawei.hms.framework.network.restclient.hwhttp.HttpContants;
import com.huawei.hms.framework.network.restclient.hwhttp.dns.DnsUtil;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.Map.Entry;
import javax.net.SocketFactory;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.StrictHostnameVerifier;

public abstract class bc {

    static class ab extends Exception {
        ab(String str) {
            super(str);
        }
    }

    public static cd ab(String str, byte[] bArr, Map<String, String> map) {
        return ab(str, bArr, (Map) map, "POST");
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static com.huawei.hianalytics.ab.bc.fg.cd ab(java.lang.String r7, byte[] r8, java.util.Map<java.lang.String, java.lang.String> r9, java.lang.String r10) {
        /*
        r2 = 0;
        r0 = android.text.TextUtils.isEmpty(r7);
        if (r0 == 0) goto L_0x0011;
    L_0x0007:
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;
        r1 = -100;
        r2 = "";
        r0.<init>(r1, r2);
    L_0x0010:
        return r0;
    L_0x0011:
        r5 = -102; // 0xffffffffffffff9a float:NaN double:NaN;
        r0 = r8.length;	 Catch:{ ab -> 0x0057, SecurityException -> 0x0076, SSLPeerUnverifiedException -> 0x0095, SSLHandshakeException -> 0x00b3, ConnectException -> 0x00d1, UnknownHostException -> 0x00ef, IOException -> 0x010d, all -> 0x012b }
        r1 = ab(r7, r0, r9, r10);	 Catch:{ ab -> 0x0057, SecurityException -> 0x0076, SSLPeerUnverifiedException -> 0x0095, SSLHandshakeException -> 0x00b3, ConnectException -> 0x00d1, UnknownHostException -> 0x00ef, IOException -> 0x010d, all -> 0x012b }
        if (r1 != 0) goto L_0x002f;
    L_0x001a:
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ ab -> 0x01ab, SecurityException -> 0x0193, SSLPeerUnverifiedException -> 0x0183, SSLHandshakeException -> 0x0173, ConnectException -> 0x0163, UnknownHostException -> 0x0157, IOException -> 0x014b, all -> 0x013a }
        r3 = -101; // 0xffffffffffffff9b float:NaN double:NaN;
        r4 = "";
        r0.<init>(r3, r4);	 Catch:{ ab -> 0x01ab, SecurityException -> 0x0193, SSLPeerUnverifiedException -> 0x0183, SSLHandshakeException -> 0x0173, ConnectException -> 0x0163, UnknownHostException -> 0x0157, IOException -> 0x014b, all -> 0x013a }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        if (r1 == 0) goto L_0x0010;
    L_0x002b:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x002f:
        r3 = r1.getOutputStream();	 Catch:{ ab -> 0x01ab, SecurityException -> 0x0193, SSLPeerUnverifiedException -> 0x0183, SSLHandshakeException -> 0x0173, ConnectException -> 0x0163, UnknownHostException -> 0x0157, IOException -> 0x014b, all -> 0x013a }
        r4 = new java.io.BufferedOutputStream;	 Catch:{ ab -> 0x01af, SecurityException -> 0x019a, SSLPeerUnverifiedException -> 0x0187, SSLHandshakeException -> 0x0177, ConnectException -> 0x0167, UnknownHostException -> 0x015a, IOException -> 0x014e }
        r4.<init>(r3);	 Catch:{ ab -> 0x01af, SecurityException -> 0x019a, SSLPeerUnverifiedException -> 0x0187, SSLHandshakeException -> 0x0177, ConnectException -> 0x0167, UnknownHostException -> 0x015a, IOException -> 0x014e }
        r4.write(r8);	 Catch:{ ab -> 0x01b5, SecurityException -> 0x01a0, SSLPeerUnverifiedException -> 0x018a, SSLHandshakeException -> 0x017a, ConnectException -> 0x016a, UnknownHostException -> 0x015c, IOException -> 0x0150, all -> 0x013f }
        r4.flush();	 Catch:{ ab -> 0x01b5, SecurityException -> 0x01a0, SSLPeerUnverifiedException -> 0x018a, SSLHandshakeException -> 0x017a, ConnectException -> 0x016a, UnknownHostException -> 0x015c, IOException -> 0x0150, all -> 0x013f }
        r2 = r1.getResponseCode();	 Catch:{ ab -> 0x01b5, SecurityException -> 0x01a0, SSLPeerUnverifiedException -> 0x018a, SSLHandshakeException -> 0x017a, ConnectException -> 0x016a, UnknownHostException -> 0x015c, IOException -> 0x0150, all -> 0x013f }
        r5 = bc(r1);	 Catch:{ ab -> 0x01b5, SecurityException -> 0x01a5, SSLPeerUnverifiedException -> 0x018e, SSLHandshakeException -> 0x017e, ConnectException -> 0x016e, UnknownHostException -> 0x015f, IOException -> 0x0153, all -> 0x013f }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ ab -> 0x01b5, SecurityException -> 0x01a5, SSLPeerUnverifiedException -> 0x018e, SSLHandshakeException -> 0x017e, ConnectException -> 0x016e, UnknownHostException -> 0x015f, IOException -> 0x0153, all -> 0x013f }
        r0.<init>(r2, r5);	 Catch:{ ab -> 0x01b5, SecurityException -> 0x01a5, SSLPeerUnverifiedException -> 0x018e, SSLHandshakeException -> 0x017e, ConnectException -> 0x016e, UnknownHostException -> 0x015f, IOException -> 0x0153, all -> 0x013f }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r4);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0010;
    L_0x0053:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x0057:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x005a:
        r0 = "HttpClient";
        r4 = "PostRequest(byte[]): No ssl socket factory set!";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r4);	 Catch:{ all -> 0x0142 }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x0142 }
        r4 = -101; // 0xffffffffffffff9b float:NaN double:NaN;
        r5 = "";
        r0.<init>(r4, r5);	 Catch:{ all -> 0x0142 }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        if (r1 == 0) goto L_0x0010;
    L_0x0072:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x0076:
        r0 = move-exception;
        r1 = r5;
        r3 = r2;
        r4 = r2;
    L_0x007a:
        r0 = "HttpClient";
        r5 = "SecurityException with HttpClient. Please check INTERNET permission.";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r5);	 Catch:{ all -> 0x0147 }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x0147 }
        r5 = "";
        r0.<init>(r1, r5);	 Catch:{ all -> 0x0147 }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r4);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r2 == 0) goto L_0x0010;
    L_0x0090:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        goto L_0x0010;
    L_0x0095:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x0098:
        r0 = "HttpClient";
        r4 = "Certificate has not been verified,Request is restricted!";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r4);	 Catch:{ all -> 0x013d }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x013d }
        r4 = "";
        r0.<init>(r5, r4);	 Catch:{ all -> 0x013d }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0010;
    L_0x00ae:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x00b3:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x00b6:
        r0 = "HttpClient";
        r4 = "Chain validation failed,Certificate expired";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r4);	 Catch:{ all -> 0x013d }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x013d }
        r4 = "";
        r0.<init>(r5, r4);	 Catch:{ all -> 0x013d }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0010;
    L_0x00cc:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x00d1:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x00d4:
        r0 = "HttpClient";
        r4 = "Network is unreachable or Connection refused";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r4);	 Catch:{ all -> 0x013d }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x013d }
        r4 = "";
        r0.<init>(r5, r4);	 Catch:{ all -> 0x013d }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0010;
    L_0x00ea:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x00ef:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x00f2:
        r0 = "HttpClient";
        r4 = "No address associated with hostname or No network";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r4);	 Catch:{ all -> 0x013d }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x013d }
        r4 = "";
        r0.<init>(r5, r4);	 Catch:{ all -> 0x013d }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0010;
    L_0x0108:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x010d:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x0110:
        r0 = "HttpClient";
        r4 = "events PostRequest(byte[]): IOException occurred.";
        com.huawei.hianalytics.ab.bc.ef.ab.cd(r0, r4);	 Catch:{ all -> 0x013d }
        r0 = new com.huawei.hianalytics.ab.bc.fg.cd;	 Catch:{ all -> 0x013d }
        r4 = "";
        r0.<init>(r5, r4);	 Catch:{ all -> 0x013d }
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0010;
    L_0x0126:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
        goto L_0x0010;
    L_0x012b:
        r0 = move-exception;
        r1 = r2;
        r3 = r2;
    L_0x012e:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r2);
        com.huawei.hianalytics.ab.bc.kl.de.ab(r3);
        if (r1 == 0) goto L_0x0139;
    L_0x0136:
        com.huawei.hianalytics.ab.bc.kl.de.ab(r1);
    L_0x0139:
        throw r0;
    L_0x013a:
        r0 = move-exception;
        r3 = r2;
        goto L_0x012e;
    L_0x013d:
        r0 = move-exception;
        goto L_0x012e;
    L_0x013f:
        r0 = move-exception;
        r2 = r4;
        goto L_0x012e;
    L_0x0142:
        r0 = move-exception;
        r6 = r2;
        r2 = r3;
        r3 = r6;
        goto L_0x012e;
    L_0x0147:
        r0 = move-exception;
        r1 = r2;
        r2 = r4;
        goto L_0x012e;
    L_0x014b:
        r0 = move-exception;
        r3 = r2;
        goto L_0x0110;
    L_0x014e:
        r0 = move-exception;
        goto L_0x0110;
    L_0x0150:
        r0 = move-exception;
        r2 = r4;
        goto L_0x0110;
    L_0x0153:
        r0 = move-exception;
        r5 = r2;
        r2 = r4;
        goto L_0x0110;
    L_0x0157:
        r0 = move-exception;
        r3 = r2;
        goto L_0x00f2;
    L_0x015a:
        r0 = move-exception;
        goto L_0x00f2;
    L_0x015c:
        r0 = move-exception;
        r2 = r4;
        goto L_0x00f2;
    L_0x015f:
        r0 = move-exception;
        r5 = r2;
        r2 = r4;
        goto L_0x00f2;
    L_0x0163:
        r0 = move-exception;
        r3 = r2;
        goto L_0x00d4;
    L_0x0167:
        r0 = move-exception;
        goto L_0x00d4;
    L_0x016a:
        r0 = move-exception;
        r2 = r4;
        goto L_0x00d4;
    L_0x016e:
        r0 = move-exception;
        r5 = r2;
        r2 = r4;
        goto L_0x00d4;
    L_0x0173:
        r0 = move-exception;
        r3 = r2;
        goto L_0x00b6;
    L_0x0177:
        r0 = move-exception;
        goto L_0x00b6;
    L_0x017a:
        r0 = move-exception;
        r2 = r4;
        goto L_0x00b6;
    L_0x017e:
        r0 = move-exception;
        r5 = r2;
        r2 = r4;
        goto L_0x00b6;
    L_0x0183:
        r0 = move-exception;
        r3 = r2;
        goto L_0x0098;
    L_0x0187:
        r0 = move-exception;
        goto L_0x0098;
    L_0x018a:
        r0 = move-exception;
        r2 = r4;
        goto L_0x0098;
    L_0x018e:
        r0 = move-exception;
        r5 = r2;
        r2 = r4;
        goto L_0x0098;
    L_0x0193:
        r0 = move-exception;
        r3 = r2;
        r4 = r2;
        r2 = r1;
        r1 = r5;
        goto L_0x007a;
    L_0x019a:
        r0 = move-exception;
        r4 = r2;
        r2 = r1;
        r1 = r5;
        goto L_0x007a;
    L_0x01a0:
        r0 = move-exception;
        r2 = r1;
        r1 = r5;
        goto L_0x007a;
    L_0x01a5:
        r0 = move-exception;
        r6 = r2;
        r2 = r1;
        r1 = r6;
        goto L_0x007a;
    L_0x01ab:
        r0 = move-exception;
        r3 = r2;
        goto L_0x005a;
    L_0x01af:
        r0 = move-exception;
        r6 = r3;
        r3 = r2;
        r2 = r6;
        goto L_0x005a;
    L_0x01b5:
        r0 = move-exception;
        r2 = r3;
        r3 = r4;
        goto L_0x005a;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.huawei.hianalytics.ab.bc.fg.bc.ab(java.lang.String, byte[], java.util.Map, java.lang.String):com.huawei.hianalytics.ab.bc.fg.cd");
    }

    private static HttpURLConnection ab(String str, int i, Map<String, String> map, String str2) {
        if (TextUtils.isEmpty(str)) {
            com.huawei.hianalytics.ab.bc.ef.ab.de("HttpClient", "CreateConnection: invalid urlPath.");
            return null;
        }
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        ab(httpURLConnection);
        httpURLConnection.setRequestMethod(str2);
        httpURLConnection.setConnectTimeout(DnsUtil.MAX_DNS_TIMEOUT);
        httpURLConnection.setReadTimeout(DnsUtil.MAX_DNS_TIMEOUT);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.setRequestProperty(HttpContants.KEY_CONTENT_TYPE, "application/json; charset=UTF-8");
        httpURLConnection.setRequestProperty("Content-Length", String.valueOf(i));
        httpURLConnection.setRequestProperty("Connection", "close");
        if (map == null || map.size() < 1) {
            return httpURLConnection;
        }
        for (Entry entry : map.entrySet()) {
            String str3 = (String) entry.getKey();
            if (!(str3 == null || TextUtils.isEmpty(str3))) {
                httpURLConnection.setRequestProperty(str3, (String) entry.getValue());
            }
        }
        return httpURLConnection;
    }

    private static void ab(HttpURLConnection httpURLConnection) {
        if (httpURLConnection instanceof HttpsURLConnection) {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) httpURLConnection;
            SocketFactory ab = ab.ab(com.huawei.hianalytics.ab.ab.bc.ik());
            if (ab == null || !(ab instanceof SSLSocketFactory)) {
                throw new ab("No ssl socket factory set");
            }
            httpsURLConnection.setSSLSocketFactory((SSLSocketFactory) ab);
            httpsURLConnection.setHostnameVerifier(new StrictHostnameVerifier());
        }
    }

    private static String bc(HttpURLConnection httpURLConnection) {
        Closeable inputStream;
        Throwable th;
        Throwable th2;
        Closeable closeable = null;
        try {
            inputStream = httpURLConnection.getInputStream();
            try {
                String ab = de.ab((InputStream) inputStream);
                de.ab(inputStream);
                return ab;
            } catch (IOException e) {
                closeable = inputStream;
                try {
                    com.huawei.hianalytics.ab.bc.ef.ab.cd("HttpClient", "When Response Content From Connection inputStream operation exception! " + httpURLConnection.getResponseCode());
                    de.ab(closeable);
                    return "";
                } catch (Throwable th3) {
                    th = th3;
                    inputStream = closeable;
                    th2 = th;
                    de.ab(inputStream);
                    throw th2;
                }
            } catch (Throwable th4) {
                th2 = th4;
                de.ab(inputStream);
                throw th2;
            }
        } catch (IOException e2) {
            com.huawei.hianalytics.ab.bc.ef.ab.cd("HttpClient", "When Response Content From Connection inputStream operation exception! " + httpURLConnection.getResponseCode());
            de.ab(closeable);
            return "";
        } catch (Throwable th32) {
            th = th32;
            inputStream = null;
            th2 = th;
            de.ab(inputStream);
            throw th2;
        }
    }
}
